// -*- coding: utf-8 -*- 
/**
 * Project: AlgorithmsLearn
 *
 * @author: yanking
 * Create time: 2022-03-08 16:04
 * IDE: IntelliJ IDEA
 * Introduction:
 */
package com.LeetCodeT.TREE;

import com.DataStruct.Tree.TwoBinaryTree.TreeNode;

@SuppressWarnings("ALL")
public class RangeSumBST {
    /**
     * 返回区域之内的节点的值
     */
    int sum = 0;

    public int rangeSumBST(TreeNode root, int low, int high) {
        if (root == null) {
            return 0;
        }
        if (root.left != null) {
            rangeSumBST(root.left, low, high);
        }
        if (root.val >= low && root.val <= high) {
            sum += root.val;
        }
        if (root.right != null) {
            rangeSumBST(root.right, low, high);
        }
        return sum;
    }
}
